//
// Created by ttao on 2022/7/20.
//

#ifndef COMPUTER_SHA_H
#define COMPUTER_SHA_H

#include <stddef.h>
#include <stdint.h>


/* ================ sha1.h ================ */
/*
 * eg:
    SHA1_CTX ctx;
    unsigned char hash[20];

    SHA1Init(&ctx);
    SHA1Update(&ctx, p, len);
    SHA1Final(hash,&ctx);
 */
typedef struct {
    uint32_t state[5];
    uint32_t count[2];
    unsigned char buffer[64];
} SHA1_CTX;

void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]);
void SHA1Init(SHA1_CTX* context);
void SHA1Update(SHA1_CTX* context, const unsigned char* data, uint32_t len);
void SHA1Final(unsigned char digest[20], SHA1_CTX* context);


/* ================ sha256.h ================ */
#define SHA256_BLOCK_SIZE 32

typedef uint8_t BYTE;
typedef uint32_t WORD;

typedef struct {
    BYTE data[64];
    WORD datalen;
    unsigned long long bitlen;
    WORD state[8];
}SHA256_CTX;

void sha256_init(SHA256_CTX *ctx);
void sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len);
void sha256_final(SHA256_CTX *ctx, BYTE hash[]);

#endif //COMPUTER_SHA_H
